<?php
/**
 * Created by PhpStorm.
 * User: lhl
 * Date: 2020/12/16
 * Time: 15:24
 * Features:信任主机
 */

namespace app\adminapiv3\validate;


use think\Validate;

class ServerAllowIpValidate extends Validate
{
    //验证规则
    protected $rule = [
        'id' => 'require|integer|egt:1',
        'ip|IP地址' => 'require|ip|max:15',
    ];

    //验证场景
    protected $scene = [
        //添加
        'add' => ['ip'],
        //修改
        'modify' => ['id','ip'],
    ];

    //错误信息
    protected $message = [
        'ip.ip' => 'IP地址格式错误',
    ];



    /**
     * 场景单独验证: 删除
     */
    public function sceneDel()
    {
        //逗号隔开的字符串
        return $this->only(['id'])
            ->remove('id', ['integer','egt'])
            ->append('id','regex:([0-9]+[,]?)+');
    }

}